package com.insectstudio.haiivloffical.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.androidquery.AQuery;
import com.insectstudio.haiivloffical.R;
import com.insectstudio.haiivloffical.model.MenuItem;

public class MenuAdapter extends ArrayAdapter<MenuItem> {
	
//	private Context context;
	private int resource;
	private ArrayList<MenuItem> objects;
	private AQuery listAq ; 
	
	public MenuAdapter(Context context, int resource,
			ArrayList<MenuItem> objects , AQuery listAq) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
//		this.context = context;
		this.resource = resource;
		this.objects = objects;
		this.listAq = listAq;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflate = (LayoutInflater) getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			 convertView = inflate.inflate(resource, null);			 
		}
		AQuery aq = listAq.recycle(convertView);
		// set text
		aq.id(R.id.txt_name).text(getItem(position).getName());
		// return view
		return convertView;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return objects.size();
	}
	
	@Override
	public MenuItem getItem(int position) {
		// TODO Auto-generated method stub
		return objects.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
